﻿//
// Copyright (c) 2024 BPer
//
#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QMainWindow>
#include <QHBoxLayout>

#include <video/BPerrecordthread.h>
#include <video/BPerrecordvideowin.h>
#include <video/BPerPlayWidget.h>
#include <video/BPerYuvPlayWidget.h>
#include <bperutil/BPerAvInfoType.h>
#include <bperutil/sys/BPerSysMessageI.h>
#include <bperutil/sys/BPerSysMessageHandle.h>
#include <bperpush/BPerPushFactory.h>
#include "BPerjanus.h"

QT_BEGIN_NAMESPACE
namespace Ui { class RecordMainWindow; }
QT_END_NAMESPACE
#define BPer_SendVideo_ 0
class RecordMainWindow : public QMainWindow, public BPerSysMessageI, public BPerSysMessageHandleI {
    Q_OBJECT

public:
    RecordMainWindow(QWidget *parent = nullptr);

    ~RecordMainWindow();

    // BPerPushHandle *m_rec;
    BPerContext *m_context;
    BPerRecordThread *m_rt;

#if BPer_OS_APPLE
    BPerYuvPlayWidget *m_win0;
#else
    BPerPlayWidget *m_win0;
#endif
    QHBoxLayout *m_hb0;
    int m_videoType;
    bool m_hasAudio;

    BPerVideoInfo m_screenInfo;
    BPerVideoInfo m_outInfo;

    BPerSysMessageHandle *m_message;


public:
    void initPreview();

    void success();

    void failure(int32_t errcode);

    void receiveSysMessage(BPerSysMessage *psm, int32_t phandleRet);

    void initVideoThread(BPerRecordThread *prt);

    void closeEvent(QCloseEvent *event);


private
    slots:
            void on_m_b_rec_clicked();

    void on_m_c_whip_clicked();

    void on_m_c_janus_clicked();

private:
    void init();

    void initRecord();

    bool m_initRecord;
    Ui::RecordMainWindow *ui;

    void closeAll();

private:
    int m_screenWidth;
    int m_screenHeight;
    int32_t m_isStartpush;
    bool m_isStartRecord;
    int32_t m_isVr;
    bool m_isDrawmouse;
    string m_url;
    int32_t m_screenInternal;
    BPerPushFactory m_pushfactory;
    BPerJanus m_janus;
};
#endif // MAINWINDOW_H
